package spring.yongongsystem.controller.merchant;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import spring.yongongsystem.POJO.dto.OrderPageQueryDTO;
import spring.yongongsystem.POJO.entity.Category;
import spring.yongongsystem.POJO.entity.Order;
import spring.yongongsystem.result.PageResult;
import spring.yongongsystem.result.Result;
import spring.yongongsystem.service.OrderService;

@RestController("merchantOrderController")
@RequestMapping("/merchant/order")
@Api(tags = "管理员订单相关接口")
@Slf4j
public class OrderController {


    @Autowired
    private OrderService orderService;

    /**
     * 订单分页查询
     * @param orderPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("订单分页查询")
    public Result<PageResult> page(OrderPageQueryDTO orderPageQueryDTO){
        log.info("订单分页查询，参数为：{}", orderPageQueryDTO);
        PageResult pageResult = orderService.pageQuery(orderPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增订单
     * @param order
     * @return
     */
    @PostMapping
    @ApiOperation("新增订单")
    public Result<String> save(@RequestBody Order order){
        log.info("新增订单：{}", order);
        orderService.save(order);
        return Result.success();
    }

    /**
     * 删除订单
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除订单")
    public Result<String> deleteById(Long id){
        log.info("删除订单：{}", id);
        orderService.deleteById(id);
        return Result.success();
    }
}
